import {put, takeEvery} from "redux-saga/effects";
import {types as pageTypes} from '@/store/common/category/pageCategory/index'
import {types as statusTypes} from '@/store/common/category/statusInfo/index'
import {load} from "@/util/global";
import {getPageCategory} from '@/util/Api';
import {actions as pageActions} from "@/store/common/category/pageCategory";
import {actions as statusActions} from "@/store/common/category/statusInfo";
import {getList} from "@/api/sysStatusInfo";

/* 文章类别 */
const pageEffects = {
    * Refresh() {
        yield load(true);
        const ajax = yield getPageCategory();
        if (ajax.success === false) {
            yield load(false);
            return;
        }
        const data = ajax.data;

        yield put(pageActions.LoadData(data));
        yield load(false);
    }
}

/* 状态类别 */
const statusEffects = {
    * Refresh() {
        yield load(true);
        // const ajax = yield getList();
        // if (ajax.success === false) {
        //     yield load(false);
        //     return;
        // }
        // const data = ajax.data;
        //
        // yield put(statusActions.LoadData(data));
        yield load(false);
    }
}

export function* pageCategory() {
    yield takeEvery(pageTypes.PAGE_CATEGORY_REFRESH, pageEffects.Refresh);
}

export function* statusCategory() {
    yield takeEvery(statusTypes.STATUS_REFRESH, statusEffects.Refresh);
}
